<%@ page language="java"
	import="com.brother.service.*,java.util.*,com.brother.model.*,com.brother.realtime.cache.*"
	contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%
	String trackId = request.getParameter("trackId");
	String mileage = request.getParameter("mileage");
	if (trackId != null && trackId.trim().length() > 0) {
		try {
			TrackerService ts = new TrackerService();
			ts.resetMileage(trackId, Float.parseFloat(mileage));
			//out.println(datas.get(i));

			out.println("1");
		} catch (Exception e) {
			out.println("0");
		}
	} else {

		com.brother.model.Customer user = (com.brother.model.Customer) session
				.getAttribute(com.brother.Constants.LOGIN_SESSTION_NAME);
		if (user == null)
			return;

		// 请求此页面的次数
		Integer count = (Integer) session.getAttribute("count");
		int limit = 2;
		if (count == null) {
			count = 1;
			session.setAttribute("count", count);
		} else { // 还没到获取缓存的时间
			count++;
			session.setAttribute("count", count);
		}

		TrackerService ts = new TrackerService();
		List<Tracker> trackers = new ArrayList();

		String uin = request.getParameter("uin");
		String isRenew = request.getParameter("isRenew");

		String lastUin = (String) session.getAttribute("lastUin");

		session.setAttribute("lastUin", uin);

		String[] imes = uin.split(",");

		for (String s : imes) {
			Tracker t = ts.getTrackerByFieldName("userTrackerId", s);
			if (t != null) {
				trackers.add(t);
			}
		}
		RealDataService s = new RealDataService();
		List<String> datas = null;
		if ((count < limit) || (lastUin == null) || (isRenew != null)
				|| (count % 30 == 0) || (!lastUin.equals(uin))) { // 还没到获取缓存的时间
			System.out.println("in position count=" + count
					+ ", isRenew=" + isRenew + ",user="
					+ user.getUserid());
			if (count % 30 == 0)
				session.setAttribute("count", 1);
			datas = s.getTrackersRealTimeData(trackers);
			GeoData geoData = GeoDataOutput.getInstance().getGeoData(
					session.getId());
			for (Tracker t : trackers) {
				geoData.getRealtimeData(t.getTrackerid());
			}
		} else { // 到了获取缓存时间
			datas = new ArrayList<String>();
			GeoData geoData = GeoDataOutput.getInstance().getGeoData(
					session.getId());
			for (Tracker t : trackers) {
				String d = geoData.getRealtimeData(t.getTrackerid());
				if (d != null) {
					datas.add(d);
				}
			}
		}
		for (int i = 0; i < datas.size(); i++) {
			out.println(datas.get(i));
		}

	}
%>
<%
	com.brother.database.DataBase.closeThreadConnection();
%>
